/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ejercicio2;
import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author User
 */
public class ejercicio8 {
    static void IntroducirAleatorioArray (int[] ar,int cant) {
        Random rand = new Random();
        for(int i=0;i<ar.length;i++) 
        {
            ar[i] = rand.nextInt(100);
        }
    }
    static void MostrarAleatorioArray (int[] ar) {
        System.out.println("Mi array original es ");
        /* *********************************
         * el for : ar es como foreach.
        ************************************/
        for(int a : ar) {
            System.out.println(a);
        }
    }
    static void OrdenarDescAleatorioArray (int[] ar, String cad ) { //[desc|asc]
        int aux,aux1;
        for(int b = 0;b<ar.length-1;b++) {
            /************************************
             * Entra si es descendente
             ************************************/
            if("desc".equals(cad))
            {
                if(ar[b] < ar[b+1])
                {
                    aux = ar[b];
                    ar[b] = ar[b+1];
                    ar[b+1] = aux;     
                }
                for(int c = b;c>0;c--)
                {
                    if(ar[c-1] < ar[c]) 
                    {
                        aux1 = ar[c-1];
                        ar[c-1] = ar[c];
                        ar[c] = aux1;
                    }
                }
            }
            /***************************************
             * Entra si es ascendete(cuaquier cosa
             ***************************************/
            else
            {
                if(ar[b] > ar[b+1])
                {
                    aux = ar[b];
                    ar[b] = ar[b+1];
                    ar[b+1] = aux;
                }
                for(int c = b;c>0;c--)
                {
                    if(ar[c-1] > ar[c]) 
                    {
                        aux1 = ar[c-1];
                        ar[c-1] = ar[c];
                        ar[c] = aux1;
                    }
                }
            } 
        }
    }
    public static void main(String[] args)  {
        Scanner reader = new Scanner(System.in);
        int cantidad,posicion;
        int[] arrayRandom;
        System.out.print("¿Cuantos numeros quieres meter?");
        cantidad = reader.nextInt();
        arrayRandom = new int[cantidad];
        IntroducirAleatorioArray(arrayRandom,cantidad);
        OrdenarDescAleatorioArray(arrayRandom,"desc");
        MostrarAleatorioArray(arrayRandom);
    }
}